#pragma once


#include <cstdint>
#include <jsoncpp/json/value.h>
#include <memory>

#include "kafka_producer.hpp"
#include "user_action.pb.h"


namespace lyt{
    class BehaviorReporter{
    private:
        KafkaProducer::ptr _producer;

    public:
        BehaviorReporter(const std::string& broker,const std::string& topic_name)
                        :_producer(std::make_shared<KafkaProducer>(broker,topic_name)){}

        void reportSubmitBehavior(
            const std::string& user_id,
            const uint32_t& problem_id,
            const std::string& submit_time,
            const std::string& accept,                 
            const int32_t difficulty,           
            const std::vector<std::string>& tags
        ){
            analytics::SubmitActionReport submit;
            submit.set_event_type(analytics::SUBMIT);
            submit.set_user_id(user_id);
            submit.set_problem_id(std::to_string(problem_id));
            submit.set_submit_time(submit_time);
            submit.set_accept(accept);
            submit.set_difficulty(difficulty);
            for(const auto& tag : tags){
                submit.add_tags(tag);
            }
            std::string payload;
            submit.SerializeToString(&payload);
            if(!_producer->send("user_id", payload)){
                errorlog << "Kafka send failed";
            }
        }
    };
};